﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Luna;

namespace TextDataExtractor.DEML {
	
	public class CompositeAction : AbstractAction {

		protected override void processChildNode(System.Xml.XmlNode child, DemlRegistry registry) {
			if (DemlFactory.Instance.isElementType(ElementType.ExtractAction, child.Name)) {
				AbstractAction action = (AbstractAction)DemlFactory.Instance.createElement(ElementType.ExtractAction, child.Name);
				if (action != null) {
					action.loadFromXml(child, registry);
					//int minOccur = pattern.getArgument("minoccur").toInt(1);
					//int maxOccur = pattern.getArgument("maxoccur").Equals("n") ? int.MaxValue : pattern.getArgument("maxoccur").toInt(1);
					//if (!(pattern is InclusionPattern) && (minOccur != 1 || maxOccur != 1)) {
					//    InclusionPattern p = new InclusionPattern(pattern, minOccur, maxOccur);
					//    pattern = p;
					//}
					Children.Add(action);
				}
			}
			else base.processChildNode(child, registry);
		}

		public override void execute(ExecutionContext context) {
			foreach (var item in getChildren<AbstractAction>()) {
				item.execute(context);
			}
		}
	}
}
